<template>
  <el-dialog title="物料产品选择"
             v-if="showFlag"
             :visible.sync="showFlag"
             :modal= false
             width="80%"
             center
  >
    <el-card style="border-radius: 10px">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
        <el-form-item label="工序编码" prop="processCode">
          <el-input
            v-model="queryParams.processCode"
            placeholder="请输入工序编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="工序名称" prop="processName">
          <el-input
            v-model="queryParams.processName"
            placeholder="请输入工序名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
      <el-table border v-loading="loading" :data="processList" @selection-change="handleSelectionChange" >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="工序编码" align="center" prop="processCode" />
        <el-table-column label="工序名称" align="center" prop="processName" :show-overflow-tooltip="true"/>
        <el-table-column label="工作站" align="center" prop="attr1" :show-overflow-tooltip="true"/>
        <el-table-column label="是否启用" align="center" prop="enableFlag">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enableFlag"/>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"/>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">确 定</el-button>
      <el-button @click="showFlag=false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {addProcess, delProcess, getProcess, listProcess, updateProcess} from "@/api/mes/pro/process";
import {genCode} from "@/api/system/autocode/rule"
import {getWsList} from "@/api/mes/md/workstation";
import {treeselect} from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "ProcessSelect",
  dicts: ['sys_yes_no', 'pro_pricing_method'],
  components: {},
  data() {
    return {
      showFlag:false,
      selectedRows:[],
      // 部门树选项
      deptOptions: undefined,
      //工作站
      workstationList: [],
      //自动生成编码
      autoGenFlag: false,
      optType: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产工序表格数据
      processList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        processCode: null,
        processName: null,
        enableFlag: 'Y',
      },
      // 表单参数
      form: {},

    };
  },
  created() {
    this.getList();

  },
  methods: {
    /** 查询生产工序列表 */
    getList() {
      this.loading = true;
      listProcess(this.queryParams).then(response => {
        this.processList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //确定选中
    confirmSelect(){
      if(this.selectedRows.length <= 0){
        this.$notify({
          title:'提示',
          type:'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected',this.selectedRows);
      this.showFlag = false;
    },
    // 取消按钮
    cancel() {
      this.showFlag = false;
      this.selectedRows=[]
    },
    // 表单重置
    reset() {
      this.form = {
        processId: null,
        processCode: null,
        processName: null,
        attention: null,
        enableFlag: 'Y',
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        pricingMethod: null,
        price: null,
        deptId: null,
        attr3: null, // 工作站
      };
      this.autoGenFlag = false;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log("多选nnnnn",selection)
      this.multipleSelection = selection;
      this.selectedRows= selection
    },

    // 查询明细按钮操作
    handleView(row) {
      this.reset();
      const processId = row.processId || this.ids;
      getProcess(processId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看工序信息";
        this.optType = "view";
      });
    },

  }
};
</script>
